{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16034c8b-1896-402c-bc96-a0401c831245",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "# 常用f-string示例\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3f39ea50-dd45-4f50-8cac-fd7713732665",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-02 06:11\n",
      "02/10/23 06:11:52\n"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "now = datetime.datetime.now()\n",
    "print(f'{now:%Y-%m-%d %H:%M}')\n",
    "print(f'{now:%d/%m/%y %H:%M:%S}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "edae161f-0cd2-44a3-91c8-cfc92892b0e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.14'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi = 3.141592653589793238462643\n",
    "f'{pi:.2f}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "040152f3-a06a-4e06-877b-4646f4e698e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.14e+03'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi = 3.141592653589793238462643\n",
    "f'{pi * 1000:.2e}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "533edfd8-e275-44c6-9653-02378de92f24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10010\n"
     ]
    }
   ],
   "source": [
    "a = 18\n",
    "print(f\"{a:b}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "700ed1a6-da00-4519-861d-bee4e5e88be7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "44\n"
     ]
    }
   ],
   "source": [
    "a = 68\n",
    "print(f\"{a:x}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7a3477b8-3392-40e1-811b-d9551678ed63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "130\n"
     ]
    }
   ],
   "source": [
    "a = 88\n",
    "print(f\"{a:o}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
